package com.example.moshudriver.protocol;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.external.activeandroid.DataBaseModel;
import com.external.activeandroid.annotation.Column;
import com.external.activeandroid.annotation.Table;

@Table(name = "SIMPLE_USER")
public class USER_DRIVER extends DataBaseModel {

	@Column(name = "role")
	public int role;

	@Column(name = "on_off")
	public int on_off;

	@Column(name = "mobile")
	public String mobile;

	@Column(name = "USER_DRIVER_id")
	public int id;

	@Column(name = "name")
	public String name;

	public void fromJson(JSONObject jsonObject) throws JSONException {
		if (null == jsonObject) {
			return;
		}

		JSONArray subItemArray;

		this.id = jsonObject.optInt("id");

		this.role = jsonObject.optInt("role");
//		this.role = jsonObject.getInt("role");

		this.on_off = jsonObject.optInt("on_off");
//		this.on_off = jsonObject.getInt("on_off");

		this.mobile = jsonObject.optString("mobile");
//		this.mobile = jsonObject.getString("mobile");
		
//		this.name = jsonObject.optString("name");
		this.name = jsonObject.getString("name");

		return;
	}

	public JSONObject toJson() throws JSONException {
		JSONObject localItemObject = new JSONObject();
		JSONArray itemJSONArray = new JSONArray();
		localItemObject.put("id", id);
		localItemObject.put("mobile", mobile);
		localItemObject.put("name", name);
		localItemObject.put("on_off", on_off);
		localItemObject.put("role", role);
		return localItemObject;
	}

}
